package com.shop.controller;

import com.github.pagehelper.PageInfo;
import com.shop.base.BaseController;
import com.shop.entity.OrderItem;
import com.shop.service.OrderItemService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/orderItem")
public class OrderItemController extends BaseController {

    private final OrderItemService orderItemService;

    /**
     * 获取所有订单项
     *
     * @param pageNum  页码
     * @param pageSize 每页数量
     * @return
     */
    @RequestMapping("/listOrderItem")
    public PageInfo<OrderItem> listOrderItem(Integer pageNum, Integer pageSize) {
        return orderItemService.listOrderItem(pageNum, pageSize);
    }

    /**
     * 根据id获取订单项
     *
     * @param id
     * @return
     */
    @RequestMapping("/getOrderItemById")
    public OrderItem getOrderItemById(Integer id) {
        return orderItemService.OrderItem(id);
    }

    /**
     * 添加订单项
     *
     * @param orderId
     * @param productId
     * @param quantity
     * @param price
     */
    @RequestMapping("/addOrderItem")
    public void addOrderItem(Integer orderId, Integer productId, Integer quantity, Double price) {
        orderItemService.addOrderItem(orderId, productId, quantity, price);
    }

    /**
     * 修改订单项
     *
     * @param id
     * @param quantity
     * @param price
     */
    @RequestMapping("/updateOrderItem")
    public void updateOrderItem(Integer id, Integer quantity, Double price) {
        orderItemService.updateOrderItem(id, quantity, price);
    }

    /**
     * 删除订单项
     *
     * @param id
     */
    @RequestMapping("/deleteOrderItem")
    public void deleteOrderItem(Integer id) {
        orderItemService.deleteOrderItem(id);
    }
}
